package com.example.controller.pc;

import com.example.common.result.Result;
import com.example.entity.dto.pc.DDPHZBlistDto;
import com.example.entity.vo.pc.*;
import com.example.mapper.pc.DDPHZBMapper;
import com.example.service.pc.DDPHZBService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/DDPHZB")
@Api(tags = "订单平衡总表")
@Validated
public class DDPHZBController {

    @Autowired
    private DDPHZBMapper ddphzbMapper;

    @Autowired
    private DDPHZBService ddphzbService;

    @ApiOperation("列表")
    @PostMapping("list")
    public Result<DDPHZBfinalListVo> list(@RequestBody DDPHZBlistDto dto) {
        DDPHZBfinalListVo res = new DDPHZBfinalListVo();
        List<DDPHZBlistVo> list = ddphzbMapper.list(dto);
        res.setList(list);
        double expectNumsSum = 0;
        double orderNumsSum = 0;
        double stockNumsSum = 0;
        double expectOutputSum = 0;
        double expectPurchaseSum = 0;
        double expectReceivingSum = 0;
        double expectPickingSum = 0;
        for(DDPHZBlistVo item : list) {
            expectNumsSum += item.getExpectNums();
            orderNumsSum += item.getOrderNums();
            stockNumsSum += item.getStockNums();
            expectOutputSum += item.getExpectOutput();
            expectPurchaseSum += item.getExpectPurchase();
            expectReceivingSum += item.getExpectReceiving();
            expectPickingSum += item.getExpectPicking();
        }
        res.setExpectNumsSum(expectNumsSum);
        res.setOrderNumsSum(orderNumsSum);
        res.setStockNumsSum(stockNumsSum);
        res.setExpectOutputSum(expectOutputSum);
        res.setExpectPurchaseSum(expectPurchaseSum);
        res.setExpectReceivingSum(expectReceivingSum);
        res.setExpectPickingSum(expectPickingSum);
        return Result.success(res);
    }

    /**
     *     // "查看销售预测";
     *     List<DDPHZBycsl> DDPHZBycsl(String productId);
     *     // "查看订单";
     *     List<DDPHZBddsl> DDPHZBddsl(String productId);
     *     // "查看库存";
     *     List<DDPHZBkcsl> DDPHZBkcsl(String productId);
     *     // "查看工单";
     *     List<DDPHZByjsc> DDPHZByjsc(String productId);
     *     // "查看工单单身";
     *     List<DDPHZByjll> DDPHZByjll(String productId);
     *     // "查看采购订单";
     *     List<DDPHZByjjh> DDPHZByjjh(String productId);
     *     // "查看请购单";
     *     List<DDPHZByjqg> DDPHZByjqg(String productId);
     */
    @ApiOperation("查看销售预测 [预测数量]")
    @PostMapping("DDPHZBycsl/{productId}")
    public Result<List<DDPHZBycsl>> DDPHZBycsl(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZBycsl(productId));
    }

    @ApiOperation("查看订单 [订单数量]")
    @PostMapping("DDPHZBddsl/{productId}")
    public Result<List<DDPHZBddsl>> DDPHZBddsl(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZBddsl(productId));
    }

    @ApiOperation("查看库存 [库存数量]")
    @PostMapping("DDPHZBkcsl/{productId}")
    public Result<List<DDPHZBkcsl>> DDPHZBkcsl(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZBkcsl(productId));
    }

    @ApiOperation("查看工单 [预计生产]")
    @PostMapping("DDPHZByjsc/{productId}")
    public Result<List<DDPHZByjsc>> DDPHZByjsc(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZByjsc(productId));
    }

    @ApiOperation("查看工单单身 [预计领料]")
    @PostMapping("DDPHZByjll/{productId}")
    public Result<List<DDPHZByjll>> DDPHZByjll(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZByjll(productId));
    }

    @ApiOperation("查看采购订单 [预计进货]")
    @PostMapping("DDPHZByjjh/{productId}")
    public Result<List<DDPHZByjjh>> DDPHZByjjh(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZByjjh(productId));
    }

    @ApiOperation("查看请购单 [预计请购]")
    @PostMapping("DDPHZByjqg/{productId}")
    public Result<List<DDPHZByjqg>> DDPHZByjqg(@PathVariable String productId) {
        return Result.success(ddphzbMapper.DDPHZByjqg(productId));
    }

}
